﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gp.Scripts.GameLogic;
using QFramework;
using UnityEngine.SceneManagement;


namespace Gp.Scripts.Core {
    public class StorageSystemConfig : SystemSystemConfig {
        protected override void OnLoad() {
            // RegisterModel(new SceneObjectModel());
            //
            // this.RegisterEvent<SceneLoadEvent>(OnSceneLoad);
            //     
                
            
                
//             this.RegisterModel(new StorageModel(new ES3Settings() {
//                 directory =
// #if UNITY_EDITOR
//                     ES3.Directory.DataPath,
// #else
//                 ES3.Directory.PersistentDataPath,
// #endif
//             }));
        }

        private void OnSceneLoad(SceneLoadEvent obj) {
            if (obj.LoadingStatus != LoadingStatus.AfterComplete) return;
            UpdateSceneObjects();
        }


        private void UpdateSceneObjects() {
            // Dictionary<string, Scene> dic = new();
            // foreach (var scene in DynamicSceneMark.Marks.Select(mark => mark.gameObject.scene)) {
            //     dic[scene.name] = scene;
            // }
            // SceneObjectModel.DynamicObjects.Clear();
            //
            // foreach (var obj in dic.Values.SelectMany(x => x.GetRootGameObjects())) {
            //     SceneObjectModel.DynamicObjects.AddRange(obj.GetComponentsInChildren<BaseDynamicObject>(true));
            // }
            //
            // foreach (var obj in SceneObjectModel.DynamicObjects) {
            //     obj.Init();
            // }
            // GC.Collect();
        }
    }
}